package com.mentorgen.tools.util.profile.bundle.obsolete;

import java.io.PrintWriter;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.mentorgen.tools.profile.Controller;

class BundleBandwidth {

	private Map<String, BundleMethodBandwidth> methods = null;

	public BundleBandwidth(){
		this.methods = new HashMap<String, BundleMethodBandwidth>();
	}

	public synchronized BundleMethodBandwidth getMethod(String _className, String _methodName){

		String key = _className + ";" + _methodName;
		BundleMethodBandwidth mbc = methods.get(key);
		if (mbc == null){
			mbc = new BundleMethodBandwidth();
			methods.put(_methodName, mbc);
		}
		return mbc;
	}

	public long getTotalInData(){

		long totalIndata = 0;

		for (String key : methods.keySet()){
			BundleMethodBandwidth mbc = methods.get(key);
			Collection<MethodBandwidth> innerMethods = mbc.getMethodContainerCollection();
			for (MethodBandwidth innerMethod : innerMethods){
				if (Controller._debug)
					System.out.println("[BDWDTH IN] " + "[" + key + ":" + mbc.totalReturn() + "]");
				totalIndata += mbc.totalReturn();
			}
		}
		if (Controller._debug)
			System.out.println("------");
		return totalIndata;
	}

	public long getTotalOutData(){

		long totalOutdata = 0;

		for (String key : methods.keySet()){
			BundleMethodBandwidth mbc = methods.get(key);
			if (Controller._debug)
				System.out.println("[BDWDTH OUT] " + "[" + key + ":" + mbc.totalOut() + "]");
			totalOutdata += mbc.totalOut();
		}
		if (Controller._debug)
			System.out.println("------");
		return totalOutdata;
	}

//	public long getAvgSrvIndata(){
//		if (Controller._debug && methods.keySet().size() != 0)
//			System.out.println("[BDWDTH AvgIN] " + "[" + (long) getTotalSrvIndata() / methodContainer.keySet().size() + "]");
//		return (methodContainer.keySet().size() == 0) ? 0 :
//			(long) getTotalSrvIndata() / methodContainer.keySet().size();
//	}
//
//	public long getAvgSrvOutdata(){
//		if (Controller._debug && methodContainer.keySet().size() != 0)
//			System.out.println("[BDWDTH AvgIN] " + "[" + (long) getTotalSrvOutdata() / methodContainer.keySet().size() + "]");
//		return (methodContainer.keySet().size() == 0) ? 0 :
//			(long) getTotalSrvOutdata() / methodContainer.keySet().size();
//	}
//
//	public long getAvgSrvCommBandwidth(){
//		if (Controller._debug && methodContainer.keySet().size() != 0)
//			System.out.println("[BDWDTH AvgTotal] [" + (long) (getTotalSrvOutdata() + getTotalSrvIndata()) / methodContainer.keySet().size() + "]");
//		return (methodContainer.keySet().size() == 0) ? 0 :
//			(long) (getTotalSrvOutdata() + getTotalSrvIndata()) / methodContainer.keySet().size();
//	}
//
//	public void printServiceInfo(PrintWriter pw){
//		for (String method : methodContainer.keySet())
//			pw.println("\t" + method + "\n" +
//					"\t\t[call  =" + methodContainer.get(method).getMthdTotalCall()+ "] \n" +
//					"\t\t[avgIn =" + methodContainer.get(method).getAvgMthdIndata()+ "] \n" +
//					"\t\t[avgOut=" + methodContainer.get(method).getAvgMthdOutdata() + "]");
//	}
}
